package com.woniuxy.rms.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.rms.advice.LogPoint;
import com.woniuxy.rms.dto.DynamicDTO;
import com.woniuxy.rms.service.DynamicService;
import com.woniuxy.rms.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/25 0025:下午 6:20  <br/>
 * Description:动态控制层
 */
@Controller
@RequestMapping("/dynamic")
public class DynamicController {
    @Autowired
    private DynamicService dynamicService;
    /**
     * Description : 动态列表分页查询  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 6:24 [Administrator]);
     * @param currentPage
     * @param pageSize
     * @return com.woniuxy.rms.util.DataResult
    */
    @GetMapping("/list")
    @ResponseBody
    @LogPoint("查询动态列表")
    public DataResult list(@RequestParam(name = "page",defaultValue = "1",required = false) Integer currentPage,
                           @RequestParam(name = "limit",defaultValue = "10",required = false) Integer pageSize){
        List<DynamicDTO> dynamics = dynamicService.findAll(currentPage,pageSize);
        PageInfo pageInfo = new PageInfo(dynamics);
        return DataResult.success(pageInfo);
    }

    /**
     * Description : 动态列表时间范围  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 6:24 [Administrator]);
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return com.woniuxy.rms.util.DataResult
     */
    @GetMapping("/scopeTime")
    @ResponseBody
    @LogPoint("动态列表时间范围查询")
    public DataResult scopeTime(@RequestParam(required = false,name = "startTime") Date startTime,
                                @RequestParam(required = false,name = "endTime") Date endTime,
                                @RequestParam(name = "page",defaultValue = "1",required = false) Integer currentPage,
                                @RequestParam(name = "limit",defaultValue = "10",required = false) Integer pageSize){
        List<DynamicDTO> dynamics = dynamicService.findScopeTime(startTime,endTime,currentPage,pageSize);
        PageInfo pageInfo = new PageInfo(dynamics);
        return DataResult.success(pageInfo);
    }

    /**
     * Description : 根据id删除单条动态  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 6:36 [Administrator]);
     * @param id
     * @return com.woniuxy.rms.util.DataResult
    */
    @DeleteMapping("/del")
    @ResponseBody
    @LogPoint("删除单条动态")
    public DataResult del(Long id){
        return dynamicService.delById(id);
    }

    /**
     * Description : 批量删除动态  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 6:47 [Administrator]);
     * @param ids
     * @return com.woniuxy.rms.util.DataResult
    */
    @DeleteMapping("/batchDel")
    @ResponseBody
    @LogPoint("批量删除动态")
    public DataResult batchDel(String ids){
        return dynamicService.batchDelByIds(ids);
    }

    /**
     * Description : 根据时间范围删除  <br/>
     * ChangeLog : 1. 创建 (2020/3/26 0026 下午 7:29 [Administrator]);
     *
     * @return com.woniuxy.rms.util.DataResult
    */
    @DeleteMapping("/batchDelByTime")
    @ResponseBody
    @LogPoint("按时间范围删除动态")
    public DataResult batchDelByTime(Date startTime,Date endTime){
        return dynamicService.batchDelByTime(startTime,endTime);
    }

}